package com.lj.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lj.mapper.ClientljMapper;
import com.lj.pojo.*;
import com.lj.service.ClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClientServiceImpl implements ClientService {
    @Autowired
    ClientljMapper clientljMapper;
    @Override
    public Clientlj login(String name, String pwd) {
        ClientljExample example=new ClientljExample();
        example.createCriteria().andClientIdEqualTo(name);
        List<Clientlj> list=clientljMapper.selectByExample(example);
        if(list.size()>0){
            Clientlj clientlj=list.get(0);
            if(clientlj.getClientPassword().equals(pwd)){
                return clientlj;
            }
        }
        return null;
    }

    @Override
    public PageInfo selectClient(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        ClientljExample example=new ClientljExample();
        example.setOrderByClause("client_id desc");
        List<Clientlj> list=clientljMapper.selectByExample(example);
        PageInfo<Clientlj> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public int insertClient(Clientlj clientlj) {
        return clientljMapper.insert(clientlj);
    }

    @Override
    public int delete(String id) {
        return clientljMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Clientlj getById(String id) {
        return clientljMapper.selectByPrimaryKey(id);
    }

    @Override
    public int update(Clientlj clientlj) {
        return clientljMapper.updateByPrimaryKey(clientlj);
    }
}
